package com.person.android.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * @autor zhaokang.
 * @time on 2015/12/19.
 */
public class NetWorkUtils {
    public static boolean isNetworkAvailable(Context context) {
        boolean isAvailable = false;

        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager == null) {
            return isAvailable;
        }
        NetworkInfo[] networkInfos = connectivityManager.getAllNetworkInfo();
        if (networkInfos == null || networkInfos.length == 0) {
            return isAvailable;
        }
        for (int i = 0; i < networkInfos.length; i++) {
            if (networkInfos[i].getState() == NetworkInfo.State.CONNECTED) {
                isAvailable = true;
                break;
            }
        }
        return isAvailable;
    }
}
